package com.coder.rental.security;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import java.security.SecureRandom;

/**
 * @author student_Hao
 * @project auto_rental
 * @date 2025/11/4
 */
@Configuration
@Data
public class PasswordConfig {
    // 通过@Value注解从应用的配置文件中动态注入加密强度值。
    @Value("${encoder.ctype.strength}")
    private int strength;

    // 通过@Value注解从应用的配置文件中动态注入加密使用的密钥。
    @Value("${encoder.ctype.secret}")
    private String secret;

    @Bean
    public BCryptPasswordEncoder passwordEncoder() {
        SecureRandom secureRandom = new SecureRandom(secret.getBytes());
        return new BCryptPasswordEncoder(strength, secureRandom);
    }


}
